//
//  PCDShareH5Plugin.m
//  PCDBankSix
//
//  Created by 冀银开发 on 2023/10/20.
//

#import "PCDShareH5Plugin.h"

@implementation PCDShareH5Plugin

- (void)handler:(id)data andContext:(PCDContext *)context ResponseCallback:(WVJBResponseCallback )responseCallback {
    //1-微信，2-朋友圈
    PCDShareScene scene = [[data objectForKey:@"channel"] intValue];
    PCDShareContentType contentType = [[data objectForKey:@"contentType"] integerValue];//0文本、1图片、2图文
    NSString *title = [data objectForKey:@"title"];//标题
    NSString *content =[data objectForKey:@"content"];//内容
    NSString *shareUrl = [data objectForKey:@"url"];//分享连接
    NSString *path =  [data objectForKey:@"imagePath"];//分享图片路径
    
    PCDShareContent *contentModel = [[PCDShareContent alloc]init];
    
    contentModel.title = title?:@"";
    contentModel.text = content?:@"";
    contentModel.scene = scene;
    contentModel.shareContentType = contentType;

    if (shareUrl) {
        contentModel.webPageURL = shareUrl;
        //        contentModel.messagePhone = @"18356530613";
        //        contentModel.target = self;
    }
    if (path) {
        dispatch_async(dispatch_get_global_queue(0, 0), ^{
            NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:path]];
            if (shareUrl) {
                contentModel.thumbnail = [UIImage imageWithData:imageData];
            }
            contentModel.image = [UIImage imageWithData:imageData];
            dispatch_async(dispatch_get_main_queue(), ^{
                [[PCDShareManager shareManager]shareToApp:PCDShareAppTypeWeChat withObject:contentModel completionHandler:^(PCDShareResponse * _Nonnull response) {
                            
                }];
            });
        });
    } else {
        [[PCDShareManager shareManager]shareToApp:PCDShareAppTypeWeChat withObject:contentModel completionHandler:^(PCDShareResponse * _Nonnull response) {
                    
        }];
    }
}

@end
